<template>
    <div>
<h2>添加康复</h2>
<table class="table">
    <tbody>
        <tr>
            <td>项目名称</td>
            <td>
                <input type="text" v-model="data.name">
            </td>
        </tr>
        <tr>
            <td>服务时长</td>
            <td>
                <input type="text" v-model="data.timeNum">小时
           </td>
        </tr>
        <tr>
            <td>服务人数</td>
            <td>
                <input type="text" v-model="data.num">人
           </td>
        </tr>
        <tr>
            <td>佣金</td>
            <td>
                <input type="text" v-model="data.price">元
           </td>
        </tr>
        <tr>
            <td>状态</td>
            <td>
                <input type="radio" v-model="data.zhuangTai" name="zhuangTai" value="1" checked>正常
                <input type="radio" v-model="data.zhuangTai" name="zhuangTai" value="2">异常
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" value="添加" @click="Add()">
            </td>
        </tr>
    </tbody>
</table>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';

const data=ref({  
  "id": 0,
  "name": "",
  "timeNum": 0,
  "num": 0,
  "price": 0,
  "zhuangTai": 1
})

const Add=()=>{
    if(data.value.name==""){
        alert("项目名称不能为空");
        return;
    }
    if(data.value.timeNum==0){
        alert("服务时长不能为0");
        return;
    }
    if(data.value.timeNum==2.1||data.value.timeNum==1.1){
        alert("服务时长必须是正数");
        return;
    }
    if(data.value.num==0){
        alert("服务人数不能为0");
        return;
    }
    if(data.value.num==1.12||data.value.num==1.123){
        alert("服务人数必须是正数");
        return;
    }
    if(data.value)
    if(data.value.price==0){
        alert("佣金不能为0");
        return;
    }
    axios.post("https://localhost:7182/api/KangFu/AddKangFu",data.value).then(res=>{
        if(res.data>0){
            alert("添加成功");
            location.href="/GetKangFu"
        }
        else{
            alert("添加失败");
        }
    })
}

</script>

<style scoped>

</style>